# @Time    : 2025/1/2 16:02
# @Author  : Zhang Yihao
my_list="This is a test string from Andrew".split()
print(my_list)
def change_lower(str_name:str):
    return str_name.lower()

print(sorted(my_list,key=change_lower))

print(my_list)
my_list.sort(key=change_lower)
print(my_list)

student_tuples=[
    ('join','A',15),
    ('jane','B',12),
    ('dave','A',10)
]
#等价于下面的lamada表达式
def func(x):
    return x[2]

print(sorted(student_tuples,key=lambda x:x[2]))

class Student:
    def __init__(self,name,grade,age):
        self.name=name
        self.grade=grade
        self.age=age

    def __repr__(self):
        """
        相对于__str__来说，更方便，可以返回非字符串类型
        :return:
        """
        return repr((self.name,self.grade,self.age))

student=Student(name='john',grade='A',age=15)
student_objects=[
    Student('john','A',15),
    Student('jane','B',12),
    Student('dave','B',10)
]
print(sorted(student_objects,key=lambda x:x.grade))

from operator import itemgetter,attrgetter
print(sorted(student_objects,key=attrgetter('grade','age')))
print(sorted(student_objects,key=itemgetter(1,2)))